<template>
  <div>
    <el-dialog title="供应商商品ID选择" width="70%" :visible.sync="dialogVisible" :before-close="closeDialog"">
      <el-table
        v-loading="loading"
        :data="serviceGoodsIdList"
        height="65vh"
        highlight-current-row
        @current-change="handleCurrentChange"
      >
        <el-table-column label="" width="55" align="center">
          <template slot-scope="scope">
            <el-radio v-model="selectedId" :label="scope.row.goodsId" class="radio-txt"></el-radio>
          </template>
        </el-table-column>
        <el-table-column label="供应商商品ID" align="center" prop="goodsId"/>
        <el-table-column label="供应商名称" align="center" prop="serviceName">
          <template slot-scope="scope">
            <span>{{ scope.row.serviceName }} ({{ scope.row.day }})</span>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        @pagination="getList"
        :autoScroll = "false"
      />

      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { goodsIdlistByServiceCode } from "@/api/shop/service";
import { getDicts as getDicts } from '@/api/system/dict/data'

export default {
  name: "service-goods-id-selector",
  components: {},
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  computed: {},
  watch: {
    dialogVisible() {
      // this.getList();
    }
  },
  data() {
    return {
      loading: true,
      serviceGoodsIdList: [],
      total: 0,
      // 查询参数
      queryParams: {
        // pageNum: 1,
        // pageSize: 10,
        serviceCode: undefined,
      },
      selectedId: null, // 单选，选中的id
      selectedItem: null, // 单选，选中的row
    };
  },
  created() {
    this.init();
  },
  mounted() {},
  methods: {
    init: function() {
      // this.getDomaninList();
      // this.getCategoryList();
      // this.getTypeList();
    },
    show(record){
      console.log(record)
      this.queryParams.serviceCode = record.serviceCode;
      this.getList();
    },
    handleCurrentChange(selection){
      console.log(selection)
      if(selection){
        this.selectedId = selection.goodsId;
        this.selectedItem = selection;
      }
    },
    /**
     * 弹窗控制
     */
    closeDialog() {
      this.$emit("update:dialogVisible", false);
    },
    // 查询供应商商品id列表
    getList() {
      this.loading = true;
      goodsIdlistByServiceCode(this.queryParams).then(response => {
        this.serviceGoodsIdList =[];
        response.forEach((item,idx)=>{
          item['no'] = idx + 1;
          this.serviceGoodsIdList.push(item);
        })
        // this.total = response.total;
        this.loading = false;
      });
    },
    /**
     * 确认选择
     */
    confirmSelect() {
      this.$emit("confirm", this.selectedItem);
      this.closeDialog();
    }
  }
};
</script>
<style lang="scss" scoped>
</style>

<style lang="scss">
  .radio-txt .el-radio__label{
    display: none;
  }
</style>
